﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using SFML.Graphics;
using SFML.Window;

namespace Theta.Animations
{
    //We need this as a Value type
    [Serializable]
    public struct Frame : ISerializable 
    {
        public Vector2i SheetPosition;
        public double Lifetime;

        public Frame(Vector2i sheetPosition, double lifetime)
        {
            Lifetime = lifetime;
            SheetPosition = sheetPosition;
        }

        public Frame(SerializationInfo info, StreamingContext context)
        {
            Lifetime = info.GetDouble("Lifetime");
            SheetPosition = (Vector2i)info.GetValue("SheetPosition", typeof(Vector2i));
        }

        public IntRect GetRect(Vector2i Size)
        {
            return (new IntRect(SheetPosition.X, SheetPosition.Y, Size.X, Size.Y));
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            //Pos: X, Y Size: X, Y
            sb.Append("Pos: ");
            sb.Append(SheetPosition.X);
            sb.Append(", ");
            sb.Append(SheetPosition.Y);
            sb.Append(" Lifetime: ");
            sb.Append(Lifetime);
            return sb.ToString();
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("SheetPosition", SheetPosition, typeof(Vector2i));
            info.AddValue("Lifetime", Lifetime);
        }
    }
}
